﻿using System.Data.SqlClient;
using System.Linq;
using GSQ.BusinessEntities;
using GSQ.DataAccess.DataSetTableAdapters;

namespace GSQ.DataAccess
{
    public class PaperConfigurationsDA
    {
        private PAPER_CONFIGURATIONSTableAdapter Adapter = new PAPER_CONFIGURATIONSTableAdapter();
        private DataSet.PAPER_CONFIGURATIONSDataTable  entities;
        private DataSet.PAPER_CONFIGURATIONSRow  entity;       

        public PAPER_CONFIGURATIONS  Get()
        {
            using (SqlConnection cnn = new SqlConnection(Connection.GetConnectionString))
            {
                try
                {
                    cnn.Open();
                    this.Adapter.Connection = cnn;
                    entity = this.Adapter.GetData().FirstOrDefault();

                    PAPER_CONFIGURATIONS  Sys;

                    if (entity != null)
                    {
                        Sys = new PAPER_CONFIGURATIONS ();
                        Sys.PAPER_NAME = entity.PAPER_NAME;
                        Sys.PAPER_ORIENTACION = entity.PAPER_ORIENTACION;
                        Sys.PAPER_SIZE = entity.PAPER_SIZE ;
                    }
                    else
                        Sys = null;

                    return Sys;
                }
                finally
                {
                    if (cnn.State != System.Data.ConnectionState.Closed)
                        cnn.Close();
                }
            }
        }     
    }
}
